﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Game
    {
        private object userName;
        private object wayName;

        public bool Gaming(Way way, User user)
        {
            int sum = 0;
            int lNum = 0;
            int nNum = 0;
            while (true)
            {
                string wayAction;
                string userAction;
                userAction = user.Action();
                Console.WriteLine(user.Name + " :出拳: " + userAction);
                wayAction = way.Action();
                Console.WriteLine(way.Name + " :出拳: " + wayAction);
                IsWin(wayAction, userAction, user.Name, ref nNum);

                //Console.WriteLine(IsWin(wayAction, userAction, user.Name, ref lNum, ref nNum));

                sum++;
                while (true)
                {
                    Console.WriteLine("是否开始下一轮？(1.继续 / 2.停止)");
                    string a = Console.ReadLine();
                    if (a == "1")
                    {
                        break;
                    }
                    else if (a == "2")
                    {
                        return EndGame(way.Name, user.Name, sum, lNum, nNum);
                    }
                    else
                    {
                        Console.WriteLine("输入错误，请重新输入！");
                        continue;
                    }
                }
            }
        }

        private void IsWin(string wayAction, string userAction, string name, ref int nNum)
        {
            throw new NotImplementedException();
        }

        private bool EndGame(string name1, string name2, int sum, int lNum, int nNum)
        {
            Console.WriteLine("=========================");
            Console.WriteLine("对战次数：" + sum);

            Console.WriteLine("姓名 \t 得分");
            Console.WriteLine(userName + "\t" + nNum);
            Console.WriteLine(wayName + "\t" + lNum);
            if (lNum > nNum)
            {
                Console.WriteLine($"{userName}赢了，{wayName}输了");
            }
            else
            {
                Console.WriteLine("平局");
            }
            while (true)
            {
                Console.WriteLine("要开始下一局吗？(y/n)");
                string a = Console.ReadLine();
                switch (a)
                {
                    case "y":
                        return true;
                    case "n":
                        return false;
                    default:
                        Console.WriteLine("选择错误，请重新输入！");
                        continue;
                }
            }
        }

        public void IsWin(string wayAction, string userAction, string name, ref int lNum, ref int nNum)
        {
            string str;
            if ((wayAction == "剪刀" && userAction == "布") || (wayAction == "石头" && userAction == "剪刀") || wayAction == "布" && userAction == "石头")
            {
                lNum++;
                Console.WriteLine($"笨蛋，{name}输了");
            }
            else if (wayAction == userAction)
            {
                Console.WriteLine($"和局，太可惜了！");
            }
            else
            {
                nNum++;
                Console.WriteLine($"恭喜，{name}赢了！");
            }

        }
    }
}
